<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="coinfaces">

        <title>设置局地ARP绑定解决网关IP地址冲突</title>

    <link rel="stylesheet" href="../../theme/css/style.css">
    <link rel="stylesheet" href="../../theme/css/pygments.css">



</head>

<body>
    <div class="content">
<h1>设置局地ARP绑定解决网关IP地址冲突</h1>    <p>
        under
            <a href="../../tags/fix/">fix</a>
    </p>
    <p>
        in <a href="../../categories/tech/">tech</a>
    </p>
    <p>Published: 2016-06-22</p>


    <p>最近发现一台电脑经常断网，检查发现网关IP地址存在冲突：</p>
<pre class="literal-block">
# arping -I eth0 x.x.x.x
ARPING x.x.x.x
60 bytes from aa:aa:aa:aa:aa:aa (x.x.x.x): index=0 time=692.552 msec
60 bytes from bb:bb:bb:bb:bb:bb (x.x.x.x): index=1 time=692.604 msec
</pre>
<p>其中“bb:bb:bb:bb:bb:bb”是真正的网关MAC地址，断网的原因是该电脑记忆了错误的网关MAC地址“aa:aa:aa:aa:aa:aa”。操作系统会自动记忆同一局域网里的主机的IP地址和MAC地址的对应关系（称为ARP缓存，ARP是Address Resolution Protocol的简称），以便和同一局域网里的主机通信，这些记录称为ARP缓存。例如计算机想和外网的一台主机通信，就要在IP层的填目标地址的IP地址，数据链路层填网关的MAC地址，让数据包先到达网关，再通过网关转发出去。如果安装了tcpdump，输入命令<tt class="docutils literal">tcpdump <span class="pre">-XX</span> <span class="pre">-i</span> eth0</tt>就会看到数据链路层的前1-6个字节和7-12个字节分别是目标主机和源主机的MAC地址。</p>
<p>当对应的ARP记录不存在或过期，源主机会在局域网里广播一条ARP请求，然后根据目标主机的回应更新ARP记录表，如果同一局域网里IP地址存在冲突，就会收到多个不同的ARP记录，这时就可能因为更新了错误的ARP记录而无法找到正确的主机。解决的方法是用arp命令指定正确的ARP记录，使用时需把eth0、bb:bb:bb:bb:bb:bb以及x.x.x.x换成真实的网络设备、MAC地址和IP地址。</p>
<pre class="literal-block">
# arp -i eth0 -s bb:bb:bb:bb:bb:bb x.x.x.x
</pre>
<div class="section" id="id1">
<h2>推荐阅读</h2>
<p><a class="reference external" href="https://tummy.com/articles/networking-basics-how-arp-works/">ARP是如何工作的</a></p>
<p>（完）</p>
</div>

    </div>
<nav class="nav sidebar">
    <div class="siteinfo">
        <div class="sitename"><a href="../..">coinfaces</a></div>
        <div class="tagline">Another Side of Life</div>
    </div>

        <a href="../../categories/">categories</a>
        <a href="../..">&larr; Home</a>
</nav><footer class="footer">
    <span>
        &copy; jpli &middot;
        under <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA 4.0</a>
    </span>
    |
    <span>
        Powered by:
        <a href="http://blog.getpelican.com/">Pelican</a>
    </span>
</footer></body>
</html>